package com.lagou.controller;

import com.lagou.service.IEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/email")
@RefreshScope
public class EmailController {

    @Autowired
    private IEmailService emailService;

    @Value("${config.email.templates.checkcode.title}")
    private String mailTitle;

    @Value("${config.email.templates.checkcode.content}")
    private String mailContent;

    @GetMapping("/{email}/{code}")
    public Boolean sendMail(@PathVariable("email") String email,
                            @PathVariable("code") String checkCode) {
        String message = String.format(mailContent, checkCode);
        return emailService.sendEmail(email, mailTitle, message);
    }
}
